﻿Imports System.Reflection
Imports System.Text
Imports System.IO
Imports LSW.Exceptions

Module AssemblyHelper
    Private CurrentAssemblyName As String = Assembly.GetExecutingAssembly().GetName().Name
    Private CurrentAssembly As Assembly = Assembly.GetExecutingAssembly()

#Region "方法"
    ''' <summary>
    ''' 在嵌入的资源文件中查找相应的图片
    ''' </summary>
    ''' <param name="name">资源图片的文件名称+扩展名</param>
    ''' <returns></returns>
    Public Function GetImage(name As String) As Drawing.Image
        Dim image__1 As Drawing.Image = Nothing
        Try
            If Not String.IsNullOrEmpty(name) Then
                Dim sb As New StringBuilder()
                If name(0) <> "."c Then
                    sb.Append(AssemblyHelper.CurrentAssemblyName + "." & name)
                Else
                    sb.Append(AssemblyHelper.CurrentAssemblyName + name)
                End If
                Using stream As Stream = CurrentAssembly.GetManifestResourceStream(sb.ToString())
                    If stream Is Nothing Then
                        Throw New Exception("加载资源文件失败，失败原因：可能丢失" & CurrentAssemblyName & ".dll文件。")
                    Else
                        image__1 = Drawing.Image.FromStream(stream)
                    End If
                End Using
            End If
        Catch ex As Exception
#If DEBUG Then
            Debug.WriteLine("AssemblyHelper.GetImage(string)->" + ex.Message)
#End If
            Throw New LSWFrameworkException(ex)
        End Try
        Return image__1
    End Function

#End Region

End Module
